﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Riel_Gestion.dao;
using Riel_Gestion.entities;
using log4net;
using Riel_Gestion.rielDataSetTableAdapters;

namespace Riel_Gestion
{
    public partial class FrmCuadroBalanceVendedores : Form
    {
        private static readonly ILog logger = LogManager.GetLogger(typeof(FrmCompra));

        DateTime fDesde;

        public DateTime FDesde
        {
            get { return fDesde; }
            set { fDesde = value; }
        }
        DateTime fHasta;

        public DateTime FHasta
        {
            get { return fHasta; }
            set { fHasta = value; }
        }

        String cliDesde;

        public String CliDesde
        {
            get { return cliDesde; }
            set { cliDesde = value; }
        }

        String cliHasta;

        public String CliHasta
        {
            get { return cliHasta; }
            set { cliHasta = value; }
        }


        public FrmCuadroBalanceVendedores()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmCuadroBalanceVendedores_Load(object sender, EventArgs e)
        {
            String totDebe  = "";
            String totHaber = "";

            rielDataSetTableAdapters.VENTATableAdapter ventaAdapter = new VENTATableAdapter();
            rielDataSet.VENTADataTable table = new rielDataSet.VENTADataTable();

            ventaAdapter.FillByIDAndDate(table, int.Parse(cliDesde), int.Parse(cliHasta), fDesde.Date, fHasta);

            foreach(DataRow fila in table)
            {
                totDebe = fila["TOTDEBE"].ToString();
                totHaber = fila["TOTHABER"].ToString();

                lblDebe.Text  = totDebe  == "" ? "0" : totDebe;
                lblHaber.Text = totHaber == "" ? "0" : totHaber;

                lblSaldo.Text = String.Format("{0}",(long.Parse(lblDebe.Text) - long.Parse(lblHaber.Text)));
            }           

            logger.Info("lblDebe: " + lblDebe.Text);
            logger.Info("lblHaber: " + lblHaber.Text);
            logger.Info("lblSaldo: " + lblSaldo.Text);           
        }
    }
}
